home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / mach / hurd / mips / __sigret.c next >
Encoding:
C/C++ Source or Header  |  1994-09-03  |  5.2 KB  |  167 lines

  1. /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <hurd.h>
  20. #include <hurd/signal.h>
  21. #include <hurd/threadvar.h>
  22. #include <stdlib.h>
  23.  
  24. int
  25. __sigreturn (struct sigcontext *scp)
  26. {
  27.   struct hurd_sigstate *ss;
  28.   mach_port_t *reply_port;
  29.  
  30.   if (scp == NULL || (scp->sc_mask & _SIG_CANT_MASK))
  31.     {
  32.       errno = EINVAL;
  33.       return -1;
  34.     }
  35.  
  36.   ss = _hurd_self_sigstate ();    /* SS->lock now locked.  */
  37.  
  38.   /* Restore the set of blocked signals, and the intr_port slot.  */
  39.   ss->blocked = scp->sc_mask;
  40.   ss->intr_port = scp->sc_intr_port;
  41.  
  42.   /* Check for pending signals that were blocked by the old set.  */
  43.   if (ss->pending & ~ss->blocked)
  44.     {
  45.       /* There are pending signals that just became unblocked.  Wake up the
  46.      signal thread to deliver them.  But first, squirrel away SCP where
  47.      the signal thread will notice it if it runs another handler, and
  48.      arrange to have us called over again in the new reality.  */
  49.       ss->context = scp;
  50.       /* Clear the intr_port slot, since we are not in fact doing
  51.      an interruptible RPC right now.  If SS->intr_port is not null,
  52.      the SCP context is doing an interruptible RPC, but the signal
  53.      thread will examine us while we are blocked in the sig_post RPC.  */
  54.       ss->intr_port = MACH_PORT_NULL;
  55.       __mutex_unlock (&ss->lock);
  56.       __sig_post (_hurd_msgport, 0, __mach_task_self ());
  57.       /* If a pending signal was handled, sig_post never returned.  */
  58.       __mutex_lock (&ss->lock);
  59.     }
  60.  
  61.   if (scp->sc_onstack)
  62.     {
  63.       ss->sigaltstack.ss_flags &= ~SA_ONSTACK; /* XXX threadvars */
  64.       /* XXX cannot unlock until off sigstack */
  65.       abort ();
  66.     }
  67.   else
  68.     __mutex_unlock (&ss->lock);
  69.  
  70.   /* Destroy the MiG reply port used by the signal handler, and restore the
  71.      reply port in use by the thread when interrupted.  */
  72.   reply_port =
  73.     (mach_port_t *) __hurd_threadvar_location (_HURD_THREADVAR_MIG_REPLY);
  74.   if (*reply_port)
  75.     __mach_port_destroy (__mach_task_self (), *reply_port);
  76.   *reply_port = scp->sc_reply_port;
  77.  
  78.   if (scp->sc_coproc_used & SC_COPROC_USE_FPU)
  79.     {
  80.       /* Restore FPU state.  */
  81. #define restore_fpr(n) \
  82.   asm volatile ("l.d $f" #n ",%0" : : "m" (scp->sc_fpr[n]))
  83.  
  84.       /* Restore floating-point registers. */
  85.       restore_fpr (0);
  86.       restore_fpr (2);
  87.       restore_fpr (4);
  88.       restore_fpr (6);
  89.       restore_fpr (8);
  90.       restore_fpr (10);
  91.       restore_fpr (12);
  92.       restore_fpr (14);
  93.       restore_fpr (16);
  94.       restore_fpr (18);
  95.       restore_fpr (20);
  96.       restore_fpr (22);
  97.       restore_fpr (24);
  98.       restore_fpr (26);
  99.       restore_fpr (28);
  100.       restore_fpr (30);
  101.  
  102.       /* Restore the floating-point control/status register ($f31).  */
  103.       asm volatile ("ctc1 %0,$f31" : : "r" (scp->sc_fpcsr));
  104.     }
  105.  
  106.   /* Load all the registers from the sigcontext.  */
  107. #define restore_gpr(n) \
  108.   asm volatile ("lw $" #n ",%0" : : "m" (scpreg->sc_gpr[n - 1]))
  109.  
  110.   {
  111.     register const struct sigcontext *const scpreg asm ("$1") = scp;
  112.     register int *at asm ("$1");
  113.  
  114.     /* First restore the multiplication result registers.  The compiler
  115.        will use some temporary registers, so we do this before restoring
  116.        the general registers.  */
  117.     asm volatile ("mtlo %0" : : "r" (scpreg->sc_mdlo));
  118.     asm volatile ("mthi %0" : : "r" (scpreg->sc_mdhi));
  119.  
  120.     /* In the word after the saved PC, store the saved $1 value.  */
  121.     (&scpreg->sc_pc)[1] = scpreg->sc_gpr[0];
  122.  
  123.     asm volatile (".set noreorder; .set noat;");
  124.  
  125.     /* Restore the normal registers.  */
  126.     restore_gpr (2);
  127.     restore_gpr (3);
  128.     restore_gpr (4);
  129.     restore_gpr (5);
  130.     restore_gpr (6);
  131.     restore_gpr (7);
  132.     restore_gpr (8);
  133.     restore_gpr (9);
  134.     restore_gpr (10);
  135.     restore_gpr (11);
  136.     restore_gpr (12);
  137.     restore_gpr (13);
  138.     restore_gpr (14);
  139.     restore_gpr (15);
  140.     restore_gpr (16);
  141.     restore_gpr (17);
  142.     restore_gpr (18);
  143.     restore_gpr (19);
  144.     restore_gpr (20);
  145.     restore_gpr (21);
  146.     restore_gpr (22);
  147.     restore_gpr (23);
  148.     restore_gpr (24);
  149.     restore_gpr (25);
  150.     /* Registers 26-27 are kernel-only.  */
  151.     restore_gpr (28);
  152.     restore_gpr (29);        /* Stack pointer.  */
  153.     restore_gpr (30);        /* Frame pointer.  */
  154.     restore_gpr (31);        /* Return address.  */
  155.  
  156.     at = &scpreg->sc_pc;
  157.     /* This is an emulated instruction that will find at the address in $1
  158.        two words: the PC value to restore, and the $1 value to restore.  */
  159.     asm volatile (".word op_sigreturn");
  160.  
  161.     asm volatile (".set reorder; .set at;");
  162.   }
  163.  
  164.   /* NOTREACHED */
  165.   return -1;
  166. }
  167.